<!--操作日志-->
<!--chenyi 2019-10-13 09:29:10-->
<template>
  <div>
    <!--搜索条件-->
    <el-form inline :model="searchParam" ref="searchParam" label-width="80px" class="search-form">
      <el-form-item label="操作用户" prop="usernameVague">
        <el-input v-model="searchParam.usernameVague" placeholder="请输入操作用户"></el-input>
      </el-form-item>
      <el-form-item label="操作" prop="operationVague">
        <el-input v-model="searchParam.operationVague" placeholder="请输入操作"></el-input>
      </el-form-item>
      <el-form-item label="开始时间" prop="searchDate">
        <es-time type="search" v-model="searchParam.searchDate"></es-time>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="searchForm">查询</el-button>
        <el-button icon="el-icon-refresh" @click="resetSearchForm">重置</el-button>
      </el-form-item>
    </el-form>
    <!--表格-->
    <el-table
      border
      :data="tableData"
      v-loading="loading"
      element-loading-text="数据加载中"
      @selection-change="handleSelectionChange"
      class="mt-20">
      <el-table-column
        prop="username"
        label="用户名"
        show-overflow-tooltip
      >
      </el-table-column>

      <el-table-column
        prop="operation"
        label="操作"
        show-overflow-tooltip
      >
      </el-table-column>

      <el-table-column
        prop="method"
        label="方法"
        show-overflow-tooltip
      >
      </el-table-column>

      <el-table-column
        prop="params"
        label="参数"
        show-overflow-tooltip
      >
      </el-table-column>

      <el-table-column
        prop="ip"
        label="ip"
        show-overflow-tooltip
      >
      </el-table-column>

      <el-table-column
        prop="remark"
        label="备注"
        show-overflow-tooltip
      >
      </el-table-column>

      <el-table-column
        prop="createTime"
        label="创建时间"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <es-time type="format" format="yyyy-MM-dd hh:mm:ss"  :value="scope.row.createTime"></es-time>
        </template>
      </el-table-column>

      <el-table-column
        fixed="right"
        label="操作"
        show-overflow-tooltip
        width="250">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="detail(scope.row)">查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
      style="margin: 20px;float: right;"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-size="searchParam.limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    <!--详情页-->
    <el-dialog :title="title" :visible="action==='info'" :before-close="handleClose">
      <el-form :model="item" label-width="100px">
        <div class="form-item-group">
          <el-form-item label="用户名" prop="username">
            <span>{{item.username||"-"}}</span>
          </el-form-item>
          <el-form-item label="操作" prop="operation">
            <span>{{item.operation||"-"}}</span>
          </el-form-item>
          <el-form-item label="方法" prop="method">
            <span>{{item.method||"-"}}</span>
          </el-form-item>
          <el-form-item label="参数" prop="params">
            <span>{{item.params||"-"}}</span>
          </el-form-item>
          <el-form-item label="ip" prop="ip">
            <span>{{item.ip||"-"}}</span>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <span>{{item.remark||"-"}}</span>
          </el-form-item>
          <el-form-item label="创建时间" prop="createTime">
            <es-time type="format" format="yyyy-MM-dd hh:mm:ss"  :value="item.createTime"></es-time>
          </el-form-item>

        </div>
        <div class="form-item-group">

        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="action = 'list'">关闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import {getList} from '../../api/sys/logApi'
  import validate from '../../libs/validate'

  export default {
    name: 'log',
    data() {
      return {
        searchParam: {//表格数据请求参数
          page: 1,
          limit: 10,
        },
        title: '',
        action: 'list',
        loading: false,
        item: {},  //修改/详情数据
        tableData: [],
        total: 0,
      }
    },
    mounted() {
      //获取数据
      this.getTableData()
    },
    methods: {
      //获取数据
      getTableData() {
        let _this = this
        _this.loading = true
        getList(_this.searchParam).then((res) => {
          if (res.code === 200) {
            _this.tableData = res.data
            console.log(_this.tableData)
            _this.total = res.total
          } else {
            this.$message.error(res.msg)
          }
          _this.loading = false
        })
      },
      detail(row) {
        this.item = row;
        this.action = 'info';
      },
      handleClose(done) {
        this.action = 'list'
        done()
      },
      //查询表格
      searchForm() {
        this.searchParam.page = 1
        //获取数据
        this.getTableData()
      },
      //重置查询表格
      resetSearchForm() {
        this.$refs['searchParam'].resetFields();
        //获取数据
        this.getTableData()
      },
      handleSizeChange(limit) {
        this.searchParam.limit = limit
        //获取数据
        this.getTableData()
      },
      handleCurrentChange(page) {
        this.searchParam.page = page
        //获取数据
        this.getTableData()
      },
      //复选框选择
      handleSelectionChange(val) {
        this.multipleSelection = val
      },
    }
  }
</script>

<style scoped>

</style>
